﻿using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Transactions;

namespace ZJRM.KingdeeK3Cloud.PlugIn.KAndOSysSynLog
{
    [Description("工具类")]
    [HotUpdate]
    public class LogTools
    {
        #region 日志操作
        /// <summary>
        /// 保存同步日志记录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="log"></param>
        /// <param name="isAsy">是否异步保存，默认异步</param>
        public static void SaveLog(Context context, SyncLog log,bool isAsy = true)
        {
            List<SqlParam> sqlParams = new List<SqlParam>();
            string sql = "";
            log.GetInsertSqlAndParams(out sqlParams, out sql);
            if (isAsy)
            {
                using (var trans = new KDTransactionScope(TransactionScopeOption.Suppress))
                {
                    int i = DBUtils.Execute(context, sql, sqlParams);
                    if (i > 0)
                    {
                        return;
                    }
                }
            }
            else
            {
                int i = DBUtils.Execute(context, sql, sqlParams);
                if (i > 0)
                {
                    return;
                }
            }         
        }

        #endregion
    }
}
